import java.util.ArrayList;

public class users60 { /*需求:
        1.main方法中定义一个集合,存入三个用户对象.
        用户属性为:id,username,password
        2.要求:定义一个方法,根据id查找对应的用户信息
        如果存在,返回索引
        如果不存在,返回-1
         */
    public static void main(String[] args) {
        ArrayList<users> list = new ArrayList<>();
        users u1 = new users("001", "zhangsan", "123");
        users u2 = new users("002", "lisi", "456");
        users u3 = new users("003", "wangwu", "789");
        list.add(u1);
        list.add(u2);
        list.add(u3);
        int a =getIndex(list,"004");
        System.out.println(a);
    }
    public static int getIndex(ArrayList<users> list, String id){
        for (int i = 0; i < list.size(); i++) {
            users u = list.get(i);
            String uid = u.getId();
            if (uid.equals(id)) {
                return i;
            }
        }
        return -1;
    }
}
